
function MyBitmap(size) {
  this.size = size;
  this.words = new Array((this.getWordIndex(size-1) + 1))
}

MyBitmap.prototype.getBit = function(bitIndex) {
  if (bitIndex < 0 || bitIndex>this.size - 1) {
    throw new RangeError('超过bitmap有效范围')
  }
  let wordIndex = this.getWordIndex(bitIndex)
  return (this.words[wordIndex] & (1 << bitIndex)) != 0;
}

MyBitmap.prototype.setBit = function(bitIndex) {
  if (bitIndex < 0 || bitIndex>this.size - 1) {
    throw new RangeError('超过bitmap有效范围')
  }
  let wordIndex = this.getWordIndex(bitIndex)
  this.words[wordIndex] |= (1 << bitIndex);
}

MyBitmap.prototype.getWordIndex = function(bitIndex) {
  return bitIndex >> 6;
}

let bitMap = new MyBitmap(128)
bitMap.setBit(126)
bitMap.setBit(75)
console.log(bitMap.getBit(126));
console.log(bitMap.getBit(78));